/*
 * @(#)LogController.java
 *
 * Copyright 2011 Xinhua Online, Inc. All rights reserved.
 */

package com.winxuan.channel.controller.commodity;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.winxuan.channel.controller.BaseController;
import com.winxuan.channel.model.commodity.CommodityLog;
import com.winxuan.channel.model.object.ChannelResult;
import com.winxuan.channel.service.commodity.LogService;
import com.winxuan.channel.support.interceptor.PaginationAware;
import com.winxuan.util.pagination.Pagination;

/**
 * 日志־
 * @author  HideHai
 * @version 1.0,2011-6-9
 */
@Controller
@RequestMapping(value="/commoditylog")
public class CommodityLogController extends BaseController implements PaginationAware{

	/**
	 *  .日志列表
	 * @param distribute
	 * @param limit
	 * @param page
	 * @return
	 * @author HideHai
	 */
	@RequestMapping(value="/list",method=RequestMethod.POST)
	public ChannelResult getLogList(@RequestParam("distribute")Integer distribute,
			@RequestParam("commodity")Integer commodity,
			@RequestParam("limit")Integer limit,
			@RequestParam("page")Integer page){
		ChannelResult channelResult = new ChannelResult();
		pagination.setPageSize(limit);
		pagination.setCurrentPage(page);
		List<CommodityLog> commodityLogs = logService.getCommodityLogByDistribute(distribute,commodity,pagination);
		if(commodityLogs != null){
			channelResult.setSuccess(true);
			channelResult.setResult(commodityLogs);
			channelResult.setTotalCount(pagination.getCount());
			return channelResult;
		}
		channelResult.setSuccess(false);
		channelResult.setResult(null);
		return channelResult;
	}
	
	/**
	 *  .根据商品查找日志
	 * @param commodity
	 * @return
	 * @author HideHai
	 */
	@RequestMapping(value="/commodity/{commodity}",method=RequestMethod.POST)
	public ChannelResult getCommodity(@RequestParam("distribute")Integer distribute,@PathVariable("commodity")Integer commodity){
		ChannelResult channelResult = new ChannelResult();
		System.out.println(distribute);
		return channelResult;
	}

	@Autowired
	private LogService logService;
	@Override
	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}
}

